package com.qzdatasoft.mcp.server.common;

import io.modelcontextprotocol.server.McpServerFeatures;
import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema.Resource;
import io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest;
import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.BiFunction;

public abstract class AbstractResourceProvider implements IMcpProvider {
    Logger log = LoggerFactory.getLogger(AbstractResourceProvider.class);

    protected abstract Resource getMeta();

    protected abstract BiFunction<McpSyncServerExchange, ReadResourceRequest, ReadResourceResult> handler();

    @Override
    public ProviderType getType() {
        return ProviderType.RESOURCE;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        McpFactory.getSyncResourceSpecificationList().add(
                new McpServerFeatures.SyncResourceSpecification(getMeta(), handler())
        );
        log.info("{} initialized.",  this.getClass().getName());
    }
}
